package android.team.app.utility;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.team.app.R;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 
 * @author sonnv6207
 * 
 *         build dialog method
 * 
 */
public class SmartDialogUtility extends Dialog {

	private TextView tvTitle, tvMessage;
	private ImageView imgIcon, imgPositiveButton, imgNagativeButton;

	private View.OnClickListener defaultDismiss = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			dismiss();
		}
	};
	
	private DialogInterface.OnDismissListener positiveDismiss, nagativeDismiss;
	private View.OnClickListener positiveButtonClick = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			setOnDismissListener(positiveDismiss);
			dismiss();
		}
	};
	
	private View.OnClickListener nagativeButtonClick = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			setOnDismissListener(nagativeDismiss);
			dismiss();
			
		}
	};
	
	
	public SmartDialogUtility(Context context,int title, int message,int iconPositiveButton) {
		super(context);
		
		//bo title default cua dialog
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.positive_custom_dialog);
		
		tvTitle = (TextView)findViewById(R.id.titleDialog);
		tvTitle.setText(context.getString(title));
		
		tvMessage = (TextView)findViewById(R.id.messageDialog);
		tvMessage.setText(context.getString(message));
		
		ImageView positiveButton = (ImageView)findViewById(R.id.btPositionDialog);
		positiveButton.setBackgroundResource(iconPositiveButton);
		positiveButton.setOnClickListener(defaultDismiss);
		
	}

	// ==========standard dialog=================//
	public static void showStandardDialog(Context context, String title,
			int icon, String message, String bt1Name,
			OnClickListener onclickBt1, String bt2Name,
			OnClickListener onclickBt2, String bt3Name,
			OnClickListener onclickBt3) {

		// step1: define dialog
		AlertDialog.Builder dialog = new AlertDialog.Builder(context);

		// step2: add attribute for header dialog
		dialog.setIcon(icon);
		dialog.setTitle(title);

		// step3: add attribute for body dialog
		dialog.setMessage(message);

		if (bt1Name != null) {
			dialog.setPositiveButton(bt1Name, onclickBt1);
		}
		if (bt2Name != null) {
			dialog.setNegativeButton(bt2Name, onclickBt2);
		}
		if (bt3Name != null) {
			dialog.setNeutralButton(bt3Name, onclickBt3);
		}

		// step4: show
		dialog.show();
	}

	// ========= custom dialog===================//

}
